package cn.edu.xust.entity;

import java.util.Arrays;
import java.util.Comparator;
import java.util.List;

// 自定义比较器
public class DeviceComparator implements Comparator<DeviceEntity> {
    @Override
    public int compare(DeviceEntity o1, DeviceEntity o2) {
        int roomNameComparison = o1.getRoomname().compareTo(o2.getRoomname());
        if (roomNameComparison != 0) {
            return roomNameComparison;
        }

        List<String> order = Arrays.asList("ele", "coldwt", "hotwt");
        int index1 = order.indexOf(o1.getType());
        int index2 = order.indexOf(o2.getType());

        if (index1 == -1 && index2 == -1) {
            return o1.getType().compareTo(o2.getType());
        } else if (index1 == -1) {
            return 1;
        } else if (index2 == -1) {
            return -1;
        } else {
            return Integer.compare(index1, index2);
        }
    }
}
